﻿using CoreShop.Library;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace CoreShop.Repository
{
    /// <summary>
    /// 文件上传帮助类
    /// </summary>
    public class MySqlHelper
    {
        /// <summary>
        /// 数据库配置连接
        /// </summary>
        //public const string mysqlString = "server=localhost; user id =root; password=kinger; database = coreshop;";
        //public const string mysqlString = "server=192.168.3.230;database=coreshop_poscy;uid=root;pwd=123456;charset='utf8';SslMode=None";
        //public const string mysqlString = "server=127.0.0.1;database=coreshop_poscy;uid=root;pwd=mysql@20231216;charset='utf8';SslMode=None";
        //public const string pgsqlString = "PORT=5620;DATABASE=tshoteldb;HOST=localhost;PASSWORD=.;USER ID=postgres";

        public static string mysqlConnect = "";

        /// <summary>
        /// 照片文件配置URL
        /// </summary>
        public const string baseUrl = "http://localhost:5622/FileVisualPath/";
        /// <summary>
        /// 上传照片URL
        /// </summary>
        public const string postUrl = "http://localhost:5622/api/Upload";

        public static string GetMysqlString()
        {
            //return "Server=39.100.91.34;Database=coreshop_poscy;Uid=strj;Pwd=st888888;CharSet=utf8;pooling=true;SslMode=None;Allow User Variables=true;Convert Zero Datetime=True;Allow Zero Datetime=True;";
            //修改
            //Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            //cfa.AppSettings.Settings["MaxNum"].Value = '20000';
            //cfa.Save(ConfigurationSaveMode.Modified);

            try
            {
                if (string.IsNullOrEmpty(mysqlConnect))
                {
                    string server = IniFiles.ReadIniData("Connect", "server");
                    string password = IniFiles.ReadIniData("Connect", "password");
                    string uid = IniFiles.ReadIniData("Connect", "uid");
                    string connect = "server={0};database=youzi_pos;uid={1};pwd={2};charset='utf8';SslMode=None;allowPublicKeyRetrieval=true;";
                    mysqlConnect = string.Format(connect, server, uid, Security.Decrypt(password));
                }
                //mysqlConnect = ConfigurationManager.AppSettings["MySqlConnect"];
                return mysqlConnect;
            }
            catch { }
            return "server=127.0.0.1;database=youzi_pos;uid=root;pwd=mysql@1688;charset='utf8';SslMode=None;allowPublicKeyRetrieval=true;";
        }
    }
}
